//
//  Home.swift
//  Exam-iOS
//
//  Created by 李胜锋 on 2018/2/28.
//  Copyright © 2018年 李胜锋. All rights reserved.
//

import Foundation

class Home {
    
    typealias HomeIndex = (news:[[String: Any]]?, examTime: [String: Any]?, entrances:[[String: Any]]?)
    static func getIndex(levelId: Int? = nil,
                         success:((HomeIndex)->Void)?,
                         failure:NetworkFailure?) {
        let path = "index"
        var parameter = [String :Any]()
        if let level = levelId {
            parameter["levelId"] = level
        }
        NetworkService.get(path, parameter: parameter, success: { (response, data) in
            guard let data = data as? [String: Any] else {  failure?(-1, "nil data"); return }
            let news = data["news"] as? [[String: Any]]
            let examTime = data["examTime"] as? [String: Any]
            let entrances = data["entrances"] as? [[String: Any]]
            let result:HomeIndex = (news, examTime, entrances)
            success?(result)
        }, failure: failure)
    }
}
